This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Cmd+Shift+Enter.
library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag(): dplyr, stats
tidyverse_packages() # which packages are in tidyverse
## [1] "broom" "dplyr" "forcats" "ggplot2" "haven"
## [6] "httr" "hms" "jsonlite" "lubridate" "magrittr"
## [11] "modelr" "purrr" "readr" "readxl" "stringr"
## [16] "tibble" "rvest" "tidyr" "xml2" "tidyverse"
# List vignettes from all *attached* packages
vignette(all = FALSE)
# List vignettes from all *installed* packages (can take a long time!):
vignette(all = TRUE)
# find vignettes of "ggplot2"
vignette(package = "ggplot2")
# view vignette "ggplot2-specs"
vignette("ggplot2-specs")
## starting httpd help server ...
## done
now look for more information on ggplot
?ggplot2
demo() # find demos for attached packages
demo(graphics) # A show of some of R's graphics capabilities, run in console
##
##
## demo(graphics)
## ---- ~~~~~~~~
##
## > # Copyright (C) 1997-2009 The R Core Team
## >
## > require(datasets)
##
## > require(grDevices); require(graphics)
##
## > ## Here is some code which illustrates some of the differences between
## > ## R and S graphics capabilities. Note that colors are generally specified
## > ## by a character string name (taken from the X11 rgb.txt file) and that line
## > ## textures are given similarly. The parameter "bg" sets the background
## > ## parameter for the plot and there is also an "fg" parameter which sets
## > ## the foreground color.
## >
## >
## > x <- stats::rnorm(50)
##
## > opar <- par(bg = "white")
##
## > plot(x, ann = FALSE, type = "n")
##
## > abline(h = 0, col = gray(.90))
##
## > lines(x, col = "green4", lty = "dotted")
##
## > points(x, bg = "limegreen", pch = 21)
##
## > title(main = "Simple Use of Color In a Plot",
## + xlab = "Just a Whisper of a Label",
## + col.main = "blue", col.lab = gray(.8),
## + cex.main = 1.2, cex.lab = 1.0, font.main = 4, font.lab = 3)
##
## > ## A little color wheel. This code just plots equally spaced hues in
## > ## a pie chart. If you have a cheap SVGA monitor (like me) you will
## > ## probably find that numerically equispaced does not mean visually
## > ## equispaced. On my display at home, these colors tend to cluster at
## > ## the RGB primaries. On the other hand on the SGI Indy at work the
## > ## effect is near perfect.
## >
## > par(bg = "gray")
##
## > pie(rep(1,24), col = rainbow(24), radius = 0.9)
##
## > title(main = "A Sample Color Wheel", cex.main = 1.4, font.main = 3)
##
## > title(xlab = "(Use this as a test of monitor linearity)",
## + cex.lab = 0.8, font.lab = 3)
##
## > ## We have already confessed to having these. This is just showing off X11
## > ## color names (and the example (from the postscript manual) is pretty "cute".
## >
## > pie.sales <- c(0.12, 0.3, 0.26, 0.16, 0.04, 0.12)
##
## > names(pie.sales) <- c("Blueberry", "Cherry",
## + "Apple", "Boston Cream", "Other", "Vanilla Cream")
##
## > pie(pie.sales,
## + col = c("purple","violetred1","green3","cornsilk","cyan","white"))
##
## > title(main = "January Pie Sales", cex.main = 1.8, font.main = 1)
##
## > title(xlab = "(Don't try this at home kids)", cex.lab = 0.8, font.lab = 3)
##
## > ## Boxplots: I couldn't resist the capability for filling the "box".
## > ## The use of color seems like a useful addition, it focuses attention
## > ## on the central bulk of the data.
## >
## > par(bg="cornsilk")
##
## > n <- 10
##
## > g <- gl(n, 100, n*100)
##
## > x <- rnorm(n*100) + sqrt(as.numeric(g))
##
## > boxplot(split(x,g), col="lavender", notch=TRUE)
##
## > title(main="Notched Boxplots", xlab="Group", font.main=4, font.lab=1)
##
## > ## An example showing how to fill between curves.
## >
## > par(bg="white")
##
## > n <- 100
##
## > x <- c(0,cumsum(rnorm(n)))
##
## > y <- c(0,cumsum(rnorm(n)))
##
## > xx <- c(0:n, n:0)
##
## > yy <- c(x, rev(y))
##
## > plot(xx, yy, type="n", xlab="Time", ylab="Distance")
##
## > polygon(xx, yy, col="gray")
##
## > title("Distance Between Brownian Motions")
##
## > ## Colored plot margins, axis labels and titles. You do need to be
## > ## careful with these kinds of effects. It's easy to go completely
## > ## over the top and you can end up with your lunch all over the keyboard.
## > ## On the other hand, my market research clients love it.
## >
## > x <- c(0.00, 0.40, 0.86, 0.85, 0.69, 0.48, 0.54, 1.09, 1.11, 1.73, 2.05, 2.02)
##
## > par(bg="lightgray")
##
## > plot(x, type="n", axes=FALSE, ann=FALSE)
##
## > usr <- par("usr")
##
## > rect(usr[1], usr[3], usr[2], usr[4], col="cornsilk", border="black")
##
## > lines(x, col="blue")
##
## > points(x, pch=21, bg="lightcyan", cex=1.25)
##
## > axis(2, col.axis="blue", las=1)
##
## > axis(1, at=1:12, lab=month.abb, col.axis="blue")
##
## > box()
##
## > title(main= "The Level of Interest in R", font.main=4, col.main="red")
##
## > title(xlab= "1996", col.lab="red")
##
## > ## A filled histogram, showing how to change the font used for the
## > ## main title without changing the other annotation.
## >
## > par(bg="cornsilk")
##
## > x <- rnorm(1000)
##
## > hist(x, xlim=range(-4, 4, x), col="lavender", main="")
##
## > title(main="1000 Normal Random Variates", font.main=3)
##
## > ## A scatterplot matrix
## > ## The good old Iris data (yet again)
## >
## > pairs(iris[1:4], main="Edgar Anderson's Iris Data", font.main=4, pch=19)
##
## > pairs(iris[1:4], main="Edgar Anderson's Iris Data", pch=21,
## + bg = c("red", "green3", "blue")[unclass(iris$Species)])
##
## > ## Contour plotting
## > ## This produces a topographic map of one of Auckland's many volcanic "peaks".
## >
## > x <- 10*1:nrow(volcano)
##
## > y <- 10*1:ncol(volcano)
##
## > lev <- pretty(range(volcano), 10)
##
## > par(bg = "lightcyan")
##
## > pin <- par("pin")
##
## > xdelta <- diff(range(x))
##
## > ydelta <- diff(range(y))
##
## > xscale <- pin[1]/xdelta
##
## > yscale <- pin[2]/ydelta
##
## > scale <- min(xscale, yscale)
##
## > xadd <- 0.5*(pin[1]/scale - xdelta)
##
## > yadd <- 0.5*(pin[2]/scale - ydelta)
##
## > plot(numeric(0), numeric(0),
## + xlim = range(x)+c(-1,1)*xadd, ylim = range(y)+c(-1,1)*yadd,
## + type = "n", ann = FALSE)
##
## > usr <- par("usr")
##
## > rect(usr[1], usr[3], usr[2], usr[4], col="green3")
##
## > contour(x, y, volcano, levels = lev, col="yellow", lty="solid", add=TRUE)
##
## > box()
##
## > title("A Topographic Map of Maunga Whau", font= 4)
##
## > title(xlab = "Meters North", ylab = "Meters West", font= 3)
##
## > mtext("10 Meter Contour Spacing", side=3, line=0.35, outer=FALSE,
## + at = mean(par("usr")[1:2]), cex=0.7, font=3)
##
## > ## Conditioning plots
## >
## > par(bg="cornsilk")
##
## > coplot(lat ~ long | depth, data = quakes, pch = 21, bg = "green3")
##
## > par(opar)
note that the pipe can be run in parts (short cut Ctrl+Shift+M, CMD+SHIFT+M )
mpg %>% select(displ, cty, hwy, year) %>% plot()
plot(select(mpg,displ,cty,hwy,year))
ggplot is part of the tidyverse and a widely used package to work with graphics note for ggplot there is “+” to combine commands, in contrast to “% > %” which is the pipe operator for commands outside ggplot
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy))
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, color = class))
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, size = class))
## Warning: Using size for a discrete variable is not advised.
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, alpha = class))
note there are only 6 different shapes, therefore “suv” has no shape and is not displayed
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy, shape = class))
## Warning: The shape palette can deal with a maximum of 6 discrete values
## because more than 6 becomes difficult to discriminate; you have 7.
## Consider specifying shapes manually if you must have them.
## Warning: Removed 62 rows containing missing values (geom_point).
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy), color = "blue")
If there is a variable value which separates data it can be used to create multiple plots rather than multiple lines in one plot.
facet_wrap wraps a 1d sequence of panels into 2d
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy)) +
facet_wrap(~ class, nrow = 2)
facet_grid forms a matrix of panels defined by row and column facetting variables.
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy)) +
facet_grid(drv ~ cyl)
different ways to present the same data
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy))
ggplot(data = mpg) +
geom_smooth(mapping = aes(x = displ, y = hwy))
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg) +
geom_smooth(mapping = aes(x = displ, y = hwy, linetype = drv, color = drv))
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg) +
geom_smooth(mapping = aes(x = displ, y = hwy, group = drv))
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg) +
geom_point(mapping = aes(x = displ, y = hwy)) +
geom_smooth(mapping = aes(x = displ, y = hwy))
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
geom_point(mapping = aes(color = class)) +
geom_smooth()
## `geom_smooth()` using method = 'loess'
ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
geom_point(mapping = aes(color = class)) +
geom_smooth(data = filter(mpg, class == "subcompact"), se = FALSE)
## `geom_smooth()` using method = 'loess'
CHEATSHEETS are at your fingertips under HELP menu of RStudio IDE or https://www.rstudio.com/resources/cheatsheets/
ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut))
ggplot(data = diamonds) +
geom_boxplot(mapping = aes(x = cut, y = price))
gives good impression of distribution
ggplot(data = diamonds) +
geom_violin(mapping = aes(x = cut, y = price, color = cut))
A histogram is a graphical representation of the distribution of numerical data.
https://de.wikipedia.org/wiki/Histogramm
ggplot(diamonds, aes(carat)) +
geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
# set binwidth
ggplot(diamonds, aes(carat)) +
geom_histogram(binwidth = 0.01)
# set number of bins
ggplot(diamonds, aes(carat)) +
geom_histogram(bins = 200)
# Rather than stacking histograms, it's easier to compare frequency
# polygons
ggplot(diamonds, aes(price, fill = cut)) +
geom_histogram(binwidth = 500)
ggplot(diamonds, aes(price, colour = cut)) +
geom_freqpoly(binwidth = 500)
work with densities, means each curve has area of one
# To make it easier to compare distributions with very different counts,
# put density on the y axis instead of the default count
ggplot(diamonds, aes(price, ..density.., colour = cut)) +
geom_freqpoly(binwidth = 500)
The empirical distribution function estimates the cumulative distribution function underlying of the points in the sample and converges with probability 1
https://de.wikipedia.org/wiki/Empirische_Verteilungsfunktion
df <- data.frame(x = rnorm(10000))
ggplot(df, aes(x)) +
geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
ggplot(df, aes(x)) + stat_ecdf(geom = "step")
p <- ggplot(df, aes(x)) + stat_ecdf()
pg <- ggplot_build(p)$data[[1]]
ggplot(pg, aes(x = x, y = 1-y )) + geom_step() + scale_y_log10()
## Warning: Transformation introduced infinite values in continuous y-axis
one more source for information https://www.rdocumentation.org
library(nycflights13)
flights
## # A tibble: 336,776 × 19
## year month day dep_time sched_dep_time dep_delay arr_time
## <int> <int> <int> <int> <int> <dbl> <int>
## 1 2013 1 1 517 515 2 830
## 2 2013 1 1 533 529 4 850
## 3 2013 1 1 542 540 2 923
## 4 2013 1 1 544 545 -1 1004
## 5 2013 1 1 554 600 -6 812
## 6 2013 1 1 554 558 -4 740
## 7 2013 1 1 555 600 -5 913
## 8 2013 1 1 557 600 -3 709
## 9 2013 1 1 557 600 -3 838
## 10 2013 1 1 558 600 -2 753
## # ... with 336,766 more rows, and 12 more variables: sched_arr_time <int>,
## # arr_delay <dbl>, carrier <chr>, flight <int>, tailnum <chr>,
## # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
## # minute <dbl>, time_hour <dttm>
filter all rows where month == 1 and day ==1, multiple filter conditions are separated by “,”
filter(flights, month == 1, day == 1)
## # A tibble: 842 × 19
## year month day dep_time sched_dep_time dep_delay arr_time
## <int> <int> <int> <int> <int> <dbl> <int>
## 1 2013 1 1 517 515 2 830
## 2 2013 1 1 533 529 4 850
## 3 2013 1 1 542 540 2 923
## 4 2013 1 1 544 545 -1 1004
## 5 2013 1 1 554 600 -6 812
## 6 2013 1 1 554 558 -4 740
## 7 2013 1 1 555 600 -5 913
## 8 2013 1 1 557 600 -3 709
## 9 2013 1 1 557 600 -3 838
## 10 2013 1 1 558 600 -2 753
## # ... with 832 more rows, and 12 more variables: sched_arr_time <int>,
## # arr_delay <dbl>, carrier <chr>, flight <int>, tailnum <chr>,
## # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
## # minute <dbl>, time_hour <dttm>
note, if you wrap the expression in () then the result will be displayed even when the result is assigned to a variable
(xmas_flights <- filter(flights, month == 12, day == 24))
## # A tibble: 761 × 19
## year month day dep_time sched_dep_time dep_delay arr_time
## <int> <int> <int> <int> <int> <dbl> <int>
## 1 2013 12 24 9 2359 10 444
## 2 2013 12 24 458 500 -2 652
## 3 2013 12 24 513 515 -2 813
## 4 2013 12 24 543 540 3 844
## 5 2013 12 24 546 550 -4 1032
## 6 2013 12 24 555 600 -5 851
## 7 2013 12 24 556 600 -4 845
## 8 2013 12 24 557 600 -3 908
## 9 2013 12 24 558 600 -2 827
## 10 2013 12 24 558 600 -2 729
## # ... with 751 more rows, and 12 more variables: sched_arr_time <int>,
## # arr_delay <dbl>, carrier <chr>, flight <int>, tailnum <chr>,
## # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
## # minute <dbl>, time_hour <dttm>
filter(flights, month == 11 | month == 12)
## # A tibble: 55,403 × 19
## year month day dep_time sched_dep_time dep_delay arr_time
## <int> <int> <int> <int> <int> <dbl> <int>
## 1 2013 11 1 5 2359 6 352
## 2 2013 11 1 35 2250 105 123
## 3 2013 11 1 455 500 -5 641
## 4 2013 11 1 539 545 -6 856
## 5 2013 11 1 542 545 -3 831
## 6 2013 11 1 549 600 -11 912
## 7 2013 11 1 550 600 -10 705
## 8 2013 11 1 554 600 -6 659
## 9 2013 11 1 554 600 -6 826
## 10 2013 11 1 554 600 -6 749
## # ... with 55,393 more rows, and 12 more variables: sched_arr_time <int>,
## # arr_delay <dbl>, carrier <chr>, flight <int>, tailnum <chr>,
## # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
## # minute <dbl>, time_hour <dttm>
the following expressions give the same result
filter(flights, !(arr_delay > 120 | dep_delay > 120))
## # A tibble: 316,050 × 19
## year month day dep_time sched_dep_time dep_delay arr_time
## <int> <int> <int> <int> <int> <dbl> <int>
## 1 2013 1 1 517 515 2 830
## 2 2013 1 1 533 529 4 850
## 3 2013 1 1 542 540 2 923
## 4 2013 1 1 544 545 -1 1004
## 5 2013 1 1 554 600 -6 812
## 6 2013 1 1 554 558 -4 740
## 7 2013 1 1 555 600 -5 913
## 8 2013 1 1 557 600 -3 709
## 9 2013 1 1 557 600 -3 838
## 10 2013 1 1 558 600 -2 753
## # ... with 316,040 more rows, and 12 more variables: sched_arr_time <int>,
## # arr_delay <dbl>, carrier <chr>, flight <int>, tailnum <chr>,
## # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
## # minute <dbl>, time_hour <dttm>
filter(flights, arr_delay <= 120, dep_delay <= 120)
## # A tibble: 316,050 × 19
## year month day dep_time sched_dep_time dep_delay arr_time
## <int> <int> <int> <int> <int> <dbl> <int>
## 1 2013 1 1 517 515 2 830
## 2 2013 1 1 533 529 4 850
## 3 2013 1 1 542 540 2 923
## 4 2013 1 1 544 545 -1 1004
## 5 2013 1 1 554 600 -6 812
## 6 2013 1 1 554 558 -4 740
## 7 2013 1 1 555 600 -5 913
## 8 2013 1 1 557 600 -3 709
## 9 2013 1 1 557 600 -3 838
## 10 2013 1 1 558 600 -2 753
## # ... with 316,040 more rows, and 12 more variables: sched_arr_time <int>,
## # arr_delay <dbl>, carrier <chr>, flight <int>, tailnum <chr>,
## # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
## # minute <dbl>, time_hour <dttm>
arrange(flights, year, month, day)
## # A tibble: 336,776 × 19
## year month day dep_time sched_dep_time dep_delay arr_time
## <int> <int> <int> <int> <int> <dbl> <int>
## 1 2013 1 1 517 515 2 830
## 2 2013 1 1 533 529 4 850
## 3 2013 1 1 542 540 2 923
## 4 2013 1 1 544 545 -1 1004
## 5 2013 1 1 554 600 -6 812
## 6 2013 1 1 554 558 -4 740
## 7 2013 1 1 555 600 -5 913
## 8 2013 1 1 557 600 -3 709
## 9 2013 1 1 557 600 -3 838
## 10 2013 1 1 558 600 -2 753
## # ... with 336,766 more rows, and 12 more variables: sched_arr_time <int>,
## # arr_delay <dbl>, carrier <chr>, flight <int>, tailnum <chr>,
## # origin <chr>, dest <chr>, air_time <dbl>, distance <dbl>, hour <dbl>,
## # minute <dbl>, time_hour <dttm>
also an easy way to bring columns in a specific order
select(flights, year, month, day)
## # A tibble: 336,776 × 3
## year month day
## <int> <int> <int>
## 1 2013 1 1
## 2 2013 1 1
## 3 2013 1 1
## 4 2013 1 1
## 5 2013 1 1
## 6 2013 1 1
## 7 2013 1 1
## 8 2013 1 1
## 9 2013 1 1
## 10 2013 1 1
## # ... with 336,766 more rows
select all but a range of columns
select(flights, -(year:day))
## # A tibble: 336,776 × 16
## dep_time sched_dep_time dep_delay arr_time sched_arr_time arr_delay
## <int> <int> <dbl> <int> <int> <dbl>
## 1 517 515 2 830 819 11
## 2 533 529 4 850 830 20
## 3 542 540 2 923 850 33
## 4 544 545 -1 1004 1022 -18
## 5 554 600 -6 812 837 -25
## 6 554 558 -4 740 728 12
## 7 555 600 -5 913 854 19
## 8 557 600 -3 709 723 -14
## 9 557 600 -3 838 846 -8
## 10 558 600 -2 753 745 8
## # ... with 336,766 more rows, and 10 more variables: carrier <chr>,
## # flight <int>, tailnum <chr>, origin <chr>, dest <chr>, air_time <dbl>,
## # distance <dbl>, hour <dbl>, minute <dbl>, time_hour <dttm>
more can be found in the cheatsheet
note the %>% operator
select(flights,
year:day,
ends_with("delay"),
distance,
air_time) %>%
mutate(
gain = arr_delay - dep_delay,
speed = distance / air_time * 60,
hours = air_time / 60,
gain_per_hour = gain / hours) %>%
select(-c(month, day, speed))
## # A tibble: 336,776 × 8
## year dep_delay arr_delay distance air_time gain hours
## <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 2013 2 11 1400 227 9 3.7833333
## 2 2013 4 20 1416 227 16 3.7833333
## 3 2013 2 33 1089 160 31 2.6666667
## 4 2013 -1 -18 1576 183 -17 3.0500000
## 5 2013 -6 -25 762 116 -19 1.9333333
## 6 2013 -4 12 719 150 16 2.5000000
## 7 2013 -5 19 1065 158 24 2.6333333
## 8 2013 -3 -14 229 53 -11 0.8833333
## 9 2013 -3 -8 944 140 -5 2.3333333
## 10 2013 -2 8 733 138 10 2.3000000
## # ... with 336,766 more rows, and 1 more variables: gain_per_hour <dbl>
if you only want to keep the new columns use “transmute()”
select(flights,
year:day,
ends_with("delay"),
distance,
air_time) %>%
transmute(
gain = arr_delay - dep_delay,
speed = distance / air_time * 60,
hours = air_time / 60,
gain_per_hour = gain / hours)
## # A tibble: 336,776 × 4
## gain speed hours gain_per_hour
## <dbl> <dbl> <dbl> <dbl>
## 1 9 370.0441 3.7833333 2.378855
## 2 16 374.2731 3.7833333 4.229075
## 3 31 408.3750 2.6666667 11.625000
## 4 -17 516.7213 3.0500000 -5.573770
## 5 -19 394.1379 1.9333333 -9.827586
## 6 16 287.6000 2.5000000 6.400000
## 7 24 404.4304 2.6333333 9.113924
## 8 -11 259.2453 0.8833333 -12.452830
## 9 -5 404.5714 2.3333333 -2.142857
## 10 10 318.6957 2.3000000 4.347826
## # ... with 336,766 more rows
the mean of all depature delays
summarise(flights, delay = mean(dep_delay, na.rm = TRUE))
## # A tibble: 1 × 1
## delay
## <dbl>
## 1 12.63907
# na.rm a logical value indicating whether NA values should be stripped before the computation proceeds.
by_day <- group_by(flights, year, month, day)
summarise(by_day, delay = mean(dep_delay, na.rm = TRUE))
## Source: local data frame [365 x 4]
## Groups: year, month [?]
##
## year month day delay
## <int> <int> <int> <dbl>
## 1 2013 1 1 11.548926
## 2 2013 1 2 13.858824
## 3 2013 1 3 10.987832
## 4 2013 1 4 8.951595
## 5 2013 1 5 5.732218
## 6 2013 1 6 7.148014
## 7 2013 1 7 5.417204
## 8 2013 1 8 2.553073
## 9 2013 1 9 2.276477
## 10 2013 1 10 2.844995
## # ... with 355 more rows
find pattern of delays during the year
by_day <- flights %>% group_by(year, month)
summarise(by_day, delay = mean(dep_delay, na.rm = TRUE)) %>% ggplot(aes( x = month, y = delay, group = month)) +
geom_col()
not_cancelled <- flights %>%
filter(!is.na(arr_delay))
not_cancelled %>%
group_by(tailnum) %>%
summarise(
delay = mean(arr_delay)
) %>%
ggplot( mapping = aes(x = delay)) +
geom_freqpoly(binwidth = 10)
there seems a few planes with very high mean delay. Lets look closer into the issue
delays <- not_cancelled %>%
group_by(tailnum) %>%
summarise(
delay = mean(arr_delay, na.rm = TRUE),
n = n()
)
ggplot(data = delays, mapping = aes(x = n, y = delay)) +
geom_point(alpha = 1/10)
the high delays are for tailnum wiht limited number of flight. Lets choose only tailnums where at least 25 flights are recorded
delays %>%
filter(n > 25) %>%
ggplot(mapping = aes(x = n, y = delay)) +
geom_point(alpha = 1/10)
what if we want to select the points under consideration not via a limit but from a plot? Use Shiny Gadgets
library(shiny)
library(miniUI)
ggbrush <- function(data, xvar, yvar) {
ui <- miniPage(
gadgetTitleBar("Drag to select points"),
miniContentPanel(
# The brush="brush" argument means we can listen for
# brush events on the plot using input$brush.
plotOutput("plot", height = "100%", brush = "brush")
)
)
server <- function(input, output, session) {
# Render the plot
output$plot <- renderPlot({
# Plot the data with x/y vars indicated by the caller.
ggplot(data, aes_string(xvar, yvar)) + geom_point()
})
# Handle the Done button being pressed.
observeEvent(input$done, {
# Return the brushed points. See ?shiny::brushedPoints.
stopApp(brushedPoints(data, input$brush, allRows = TRUE))
})
}
runGadget(ui, server)
}
# pick_points(mtcars, ~wt, ~mpg)
brushed_points <- ggbrush(delays, "n", "delay")
##
## Listening on http://127.0.0.1:3405
brushed_points %>% ggplot(mapping = aes(x = n, y = delay, color = selected_)) +
geom_point(alpha = 1/10)
brushed_points %>% filter(selected_ ==TRUE) %>% ggplot(mapping = aes(x = n, y = delay, color = selected_)) +
geom_point(alpha = 1/10)
the data set nycflights13 has four tibbles (dataframes)
airlines
## # A tibble: 16 × 2
## carrier name
## <chr> <chr>
## 1 9E Endeavor Air Inc.
## 2 AA American Airlines Inc.
## 3 AS Alaska Airlines Inc.
## 4 B6 JetBlue Airways
## 5 DL Delta Air Lines Inc.
## 6 EV ExpressJet Airlines Inc.
## 7 F9 Frontier Airlines Inc.
## 8 FL AirTran Airways Corporation
## 9 HA Hawaiian Airlines Inc.
## 10 MQ Envoy Air
## 11 OO SkyWest Airlines Inc.
## 12 UA United Air Lines Inc.
## 13 US US Airways Inc.
## 14 VX Virgin America
## 15 WN Southwest Airlines Co.
## 16 YV Mesa Airlines Inc.
airports
## # A tibble: 1,458 × 8
## faa name lat lon alt tz
## <chr> <chr> <dbl> <dbl> <int> <dbl>
## 1 04G Lansdowne Airport 41.13047 -80.61958 1044 -5
## 2 06A Moton Field Municipal Airport 32.46057 -85.68003 264 -6
## 3 06C Schaumburg Regional 41.98934 -88.10124 801 -6
## 4 06N Randall Airport 41.43191 -74.39156 523 -5
## 5 09J Jekyll Island Airport 31.07447 -81.42778 11 -5
## 6 0A9 Elizabethton Municipal Airport 36.37122 -82.17342 1593 -5
## 7 0G6 Williams County Airport 41.46731 -84.50678 730 -5
## 8 0G7 Finger Lakes Regional Airport 42.88356 -76.78123 492 -5
## 9 0P2 Shoestring Aviation Airfield 39.79482 -76.64719 1000 -5
## 10 0S9 Jefferson County Intl 48.05381 -122.81064 108 -8
## # ... with 1,448 more rows, and 2 more variables: dst <chr>, tzone <chr>
planes
## # A tibble: 3,322 × 9
## tailnum year type manufacturer model
## <chr> <int> <chr> <chr> <chr>
## 1 N10156 2004 Fixed wing multi engine EMBRAER EMB-145XR
## 2 N102UW 1998 Fixed wing multi engine AIRBUS INDUSTRIE A320-214
## 3 N103US 1999 Fixed wing multi engine AIRBUS INDUSTRIE A320-214
## 4 N104UW 1999 Fixed wing multi engine AIRBUS INDUSTRIE A320-214
## 5 N10575 2002 Fixed wing multi engine EMBRAER EMB-145LR
## 6 N105UW 1999 Fixed wing multi engine AIRBUS INDUSTRIE A320-214
## 7 N107US 1999 Fixed wing multi engine AIRBUS INDUSTRIE A320-214
## 8 N108UW 1999 Fixed wing multi engine AIRBUS INDUSTRIE A320-214
## 9 N109UW 1999 Fixed wing multi engine AIRBUS INDUSTRIE A320-214
## 10 N110UW 1999 Fixed wing multi engine AIRBUS INDUSTRIE A320-214
## # ... with 3,312 more rows, and 4 more variables: engines <int>,
## # seats <int>, speed <int>, engine <chr>
weather
## # A tibble: 26,130 × 15
## origin year month day hour temp dewp humid wind_dir wind_speed
## <chr> <dbl> <dbl> <int> <int> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 EWR 2013 1 1 0 37.04 21.92 53.97 230 10.35702
## 2 EWR 2013 1 1 1 37.04 21.92 53.97 230 13.80936
## 3 EWR 2013 1 1 2 37.94 21.92 52.09 230 12.65858
## 4 EWR 2013 1 1 3 37.94 23.00 54.51 230 13.80936
## 5 EWR 2013 1 1 4 37.94 24.08 57.04 240 14.96014
## 6 EWR 2013 1 1 6 39.02 26.06 59.37 270 10.35702
## 7 EWR 2013 1 1 7 39.02 26.96 61.63 250 8.05546
## 8 EWR 2013 1 1 8 39.02 28.04 64.43 240 11.50780
## 9 EWR 2013 1 1 9 39.92 28.04 62.21 250 12.65858
## 10 EWR 2013 1 1 10 39.02 28.04 64.43 260 12.65858
## # ... with 26,120 more rows, and 5 more variables: wind_gust <dbl>,
## # precip <dbl>, pressure <dbl>, visib <dbl>, time_hour <dttm>
library(visNetwork)
# this function creates a data.frame with the name of the data.frame and the names of the columns of that data.frame
create_df_of_names = function(df, name){
data.frame(from = name, to = names(df))
}
# create a names list of the data.frames
a <- list(flights = flights,airlines = airlines, airports = airports, weather = weather,
planes = planes)
# and map them to build one data.frame with two columns
# - from contains all data.frame names
# - to contains all column names
edge <- map2_df(a,names(a), create_df_of_names)
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
## Warning in bind_rows_(x, .id): Unequal factor levels: coercing to character
# create a visNetwork
nodesFrom <- edge %>% cbind(unlist(.$from),"Table") %>% select(3,4) %>% data.frame
nodesTo <- edge %>% cbind(unlist(.$to),"Attribute") %>% select(3,4) %>% data.frame
names(nodesFrom) <- c("id", "group")
names(nodesTo) <- c("id", "group")
nodes <- rbind(nodesFrom,nodesTo) %>% unique()
nodes$id <- as.character((nodes$id))
nodes <- nodes %>% unique() %>% arrange(id)
visNetwork(nodes, edge)%>%
visOptions(highlightNearest = list(enabled = TRUE, degree = 2), nodesIdSelection = TRUE) %>%
visEdges(arrows = "to") %>%
visGroups(groupname = "Table", shape = "icon", icon = list(code = "f114", color = "green",size = 75)) %>%
visGroups(groupname = "Attribute", shape = "icon", icon = list(code = "f115", color = "lightgreen", size = 45)) %>%
addFontAwesome()
# list of icons http://astronautweb.co/snippet/font-awesome/
first we need to join flights with planes
flight_planes <- left_join(flights, planes, by = "tailnum")
flight_planes %>% group_by(manufacturer) %>% summarise(delay_per_flight = sum(arr_delay, na.rm = TRUE)/ n(),number_of_flights = n()) %>% arrange(desc(delay_per_flight))
## # A tibble: 36 × 3
## manufacturer delay_per_flight number_of_flights
## <chr> <dbl> <int>
## 1 AGUSTA SPA 29.687500 32
## 2 CANADAIR 15.601004 1594
## 3 EMBRAER 13.384952 66068
## 4 AVIAT AIRCRAFT INC 11.611111 18
## 5 FRIEDEMANN JON 11.507937 63
## 6 BARKER JACK L 11.027778 252
## 7 LAMBERT RICHARD 8.907407 54
## 8 CESSNA 8.164134 658
## 9 CIRRUS DESIGN CORP 8.109966 291
## 10 ROBINSON HELICOPTER CO 8.041958 286
## # ... with 26 more rows
first we need to join flights with planes
flight_airlines <- left_join(flights, airlines)
## Joining, by = "carrier"
flight_airlines %>% group_by(name) %>% summarise(delay_per_flight = sum(arr_delay, na.rm = TRUE)/ n(),number_of_flights = n()) %>% arrange(desc(delay_per_flight))
## # A tibble: 16 × 3
## name delay_per_flight number_of_flights
## <chr> <dbl> <int>
## 1 Frontier Airlines Inc. 21.7927007 685
## 2 AirTran Airways Corporation 19.5914110 3260
## 3 ExpressJet Airlines Inc. 14.9027006 54173
## 4 Mesa Airlines Inc. 14.0815308 601
## 5 SkyWest Airlines Inc. 10.8125000 32
## 6 Envoy Air 10.2196083 26397
## 7 Southwest Airlines Co. 9.4675356 12275
## 8 JetBlue Airways 9.3565297 54635
## 9 Endeavor Air Inc. 6.9135428 18460
## 10 United Air Lines Inc. 3.5044575 58665
## 11 US Airways Inc. 2.0564862 20536
## 12 Virgin America 1.7487408 5162
## 13 Delta Air Lines Inc. 1.6288921 48110
## 14 American Airlines Inc. 0.3555868 32729
## 15 Hawaiian Airlines Inc. -6.9152047 342
## 16 Alaska Airlines Inc. -9.8613445 714
for some operations the tidy wide format is not suitable as input to an operation, then a “long” version of the data.frame can be generated using the “melt” command. A further example will be shown in EuropeLeagueTransfers.Rmd and further information on the topic can be found at http://seananderson.ca/2013/10/19/reshape.html
library(reshape2)
##
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
##
## smiths
names(airquality) <- tolower(names(airquality))
aqm <- melt(airquality, id=c("month", "day"),
variable.name = "climate_variable",
value.name = "climate_value")
airquality
## ozone solar.r wind temp month day
## 1 41 190 7.4 67 5 1
## 2 36 118 8.0 72 5 2
## 3 12 149 12.6 74 5 3
## 4 18 313 11.5 62 5 4
## 5 NA NA 14.3 56 5 5
## 6 28 NA 14.9 66 5 6
## 7 23 299 8.6 65 5 7
## 8 19 99 13.8 59 5 8
## 9 8 19 20.1 61 5 9
## 10 NA 194 8.6 69 5 10
## 11 7 NA 6.9 74 5 11
## 12 16 256 9.7 69 5 12
## 13 11 290 9.2 66 5 13
## 14 14 274 10.9 68 5 14
## 15 18 65 13.2 58 5 15
## 16 14 334 11.5 64 5 16
## 17 34 307 12.0 66 5 17
## 18 6 78 18.4 57 5 18
## 19 30 322 11.5 68 5 19
## 20 11 44 9.7 62 5 20
## 21 1 8 9.7 59 5 21
## 22 11 320 16.6 73 5 22
## 23 4 25 9.7 61 5 23
## 24 32 92 12.0 61 5 24
## 25 NA 66 16.6 57 5 25
## 26 NA 266 14.9 58 5 26
## 27 NA NA 8.0 57 5 27
## 28 23 13 12.0 67 5 28
## 29 45 252 14.9 81 5 29
## 30 115 223 5.7 79 5 30
## 31 37 279 7.4 76 5 31
## 32 NA 286 8.6 78 6 1
## 33 NA 287 9.7 74 6 2
## 34 NA 242 16.1 67 6 3
## 35 NA 186 9.2 84 6 4
## 36 NA 220 8.6 85 6 5
## 37 NA 264 14.3 79 6 6
## 38 29 127 9.7 82 6 7
## 39 NA 273 6.9 87 6 8
## 40 71 291 13.8 90 6 9
## 41 39 323 11.5 87 6 10
## 42 NA 259 10.9 93 6 11
## 43 NA 250 9.2 92 6 12
## 44 23 148 8.0 82 6 13
## 45 NA 332 13.8 80 6 14
## 46 NA 322 11.5 79 6 15
## 47 21 191 14.9 77 6 16
## 48 37 284 20.7 72 6 17
## 49 20 37 9.2 65 6 18
## 50 12 120 11.5 73 6 19
## 51 13 137 10.3 76 6 20
## 52 NA 150 6.3 77 6 21
## 53 NA 59 1.7 76 6 22
## 54 NA 91 4.6 76 6 23
## 55 NA 250 6.3 76 6 24
## 56 NA 135 8.0 75 6 25
## 57 NA 127 8.0 78 6 26
## 58 NA 47 10.3 73 6 27
## 59 NA 98 11.5 80 6 28
## 60 NA 31 14.9 77 6 29
## 61 NA 138 8.0 83 6 30
## 62 135 269 4.1 84 7 1
## 63 49 248 9.2 85 7 2
## 64 32 236 9.2 81 7 3
## 65 NA 101 10.9 84 7 4
## 66 64 175 4.6 83 7 5
## 67 40 314 10.9 83 7 6
## 68 77 276 5.1 88 7 7
## 69 97 267 6.3 92 7 8
## 70 97 272 5.7 92 7 9
## 71 85 175 7.4 89 7 10
## 72 NA 139 8.6 82 7 11
## 73 10 264 14.3 73 7 12
## 74 27 175 14.9 81 7 13
## 75 NA 291 14.9 91 7 14
## 76 7 48 14.3 80 7 15
## 77 48 260 6.9 81 7 16
## 78 35 274 10.3 82 7 17
## 79 61 285 6.3 84 7 18
## 80 79 187 5.1 87 7 19
## 81 63 220 11.5 85 7 20
## 82 16 7 6.9 74 7 21
## 83 NA 258 9.7 81 7 22
## 84 NA 295 11.5 82 7 23
## 85 80 294 8.6 86 7 24
## 86 108 223 8.0 85 7 25
## 87 20 81 8.6 82 7 26
## 88 52 82 12.0 86 7 27
## 89 82 213 7.4 88 7 28
## 90 50 275 7.4 86 7 29
## 91 64 253 7.4 83 7 30
## 92 59 254 9.2 81 7 31
## 93 39 83 6.9 81 8 1
## 94 9 24 13.8 81 8 2
## 95 16 77 7.4 82 8 3
## 96 78 NA 6.9 86 8 4
## 97 35 NA 7.4 85 8 5
## 98 66 NA 4.6 87 8 6
## 99 122 255 4.0 89 8 7
## 100 89 229 10.3 90 8 8
## 101 110 207 8.0 90 8 9
## 102 NA 222 8.6 92 8 10
## 103 NA 137 11.5 86 8 11
## 104 44 192 11.5 86 8 12
## 105 28 273 11.5 82 8 13
## 106 65 157 9.7 80 8 14
## 107 NA 64 11.5 79 8 15
## 108 22 71 10.3 77 8 16
## 109 59 51 6.3 79 8 17
## 110 23 115 7.4 76 8 18
## 111 31 244 10.9 78 8 19
## 112 44 190 10.3 78 8 20
## 113 21 259 15.5 77 8 21
## 114 9 36 14.3 72 8 22
## 115 NA 255 12.6 75 8 23
## 116 45 212 9.7 79 8 24
## 117 168 238 3.4 81 8 25
## 118 73 215 8.0 86 8 26
## 119 NA 153 5.7 88 8 27
## 120 76 203 9.7 97 8 28
## 121 118 225 2.3 94 8 29
## 122 84 237 6.3 96 8 30
## 123 85 188 6.3 94 8 31
## 124 96 167 6.9 91 9 1
## 125 78 197 5.1 92 9 2
## 126 73 183 2.8 93 9 3
## 127 91 189 4.6 93 9 4
## 128 47 95 7.4 87 9 5
## 129 32 92 15.5 84 9 6
## 130 20 252 10.9 80 9 7
## 131 23 220 10.3 78 9 8
## 132 21 230 10.9 75 9 9
## 133 24 259 9.7 73 9 10
## 134 44 236 14.9 81 9 11
## 135 21 259 15.5 76 9 12
## 136 28 238 6.3 77 9 13
## 137 9 24 10.9 71 9 14
## 138 13 112 11.5 71 9 15
## 139 46 237 6.9 78 9 16
## 140 18 224 13.8 67 9 17
## 141 13 27 10.3 76 9 18
## 142 24 238 10.3 68 9 19
## 143 16 201 8.0 82 9 20
## 144 13 238 12.6 64 9 21
## 145 23 14 9.2 71 9 22
## 146 36 139 10.3 81 9 23
## 147 7 49 10.3 69 9 24
## 148 14 20 16.6 63 9 25
## 149 30 193 6.9 70 9 26
## 150 NA 145 13.2 77 9 27
## 151 14 191 14.3 75 9 28
## 152 18 131 8.0 76 9 29
## 153 20 223 11.5 68 9 30
aqm
## month day climate_variable climate_value
## 1 5 1 ozone 41.0
## 2 5 2 ozone 36.0
## 3 5 3 ozone 12.0
## 4 5 4 ozone 18.0
## 5 5 5 ozone NA
## 6 5 6 ozone 28.0
## 7 5 7 ozone 23.0
## 8 5 8 ozone 19.0
## 9 5 9 ozone 8.0
## 10 5 10 ozone NA
## 11 5 11 ozone 7.0
## 12 5 12 ozone 16.0
## 13 5 13 ozone 11.0
## 14 5 14 ozone 14.0
## 15 5 15 ozone 18.0
## 16 5 16 ozone 14.0
## 17 5 17 ozone 34.0
## 18 5 18 ozone 6.0
## 19 5 19 ozone 30.0
## 20 5 20 ozone 11.0
## 21 5 21 ozone 1.0
## 22 5 22 ozone 11.0
## 23 5 23 ozone 4.0
## 24 5 24 ozone 32.0
## 25 5 25 ozone NA
## 26 5 26 ozone NA
## 27 5 27 ozone NA
## 28 5 28 ozone 23.0
## 29 5 29 ozone 45.0
## 30 5 30 ozone 115.0
## 31 5 31 ozone 37.0
## 32 6 1 ozone NA
## 33 6 2 ozone NA
## 34 6 3 ozone NA
## 35 6 4 ozone NA
## 36 6 5 ozone NA
## 37 6 6 ozone NA
## 38 6 7 ozone 29.0
## 39 6 8 ozone NA
## 40 6 9 ozone 71.0
## 41 6 10 ozone 39.0
## 42 6 11 ozone NA
## 43 6 12 ozone NA
## 44 6 13 ozone 23.0
## 45 6 14 ozone NA
## 46 6 15 ozone NA
## 47 6 16 ozone 21.0
## 48 6 17 ozone 37.0
## 49 6 18 ozone 20.0
## 50 6 19 ozone 12.0
## 51 6 20 ozone 13.0
## 52 6 21 ozone NA
## 53 6 22 ozone NA
## 54 6 23 ozone NA
## 55 6 24 ozone NA
## 56 6 25 ozone NA
## 57 6 26 ozone NA
## 58 6 27 ozone NA
## 59 6 28 ozone NA
## 60 6 29 ozone NA
## 61 6 30 ozone NA
## 62 7 1 ozone 135.0
## 63 7 2 ozone 49.0
## 64 7 3 ozone 32.0
## 65 7 4 ozone NA
## 66 7 5 ozone 64.0
## 67 7 6 ozone 40.0
## 68 7 7 ozone 77.0
## 69 7 8 ozone 97.0
## 70 7 9 ozone 97.0
## 71 7 10 ozone 85.0
## 72 7 11 ozone NA
## 73 7 12 ozone 10.0
## 74 7 13 ozone 27.0
## 75 7 14 ozone NA
## 76 7 15 ozone 7.0
## 77 7 16 ozone 48.0
## 78 7 17 ozone 35.0
## 79 7 18 ozone 61.0
## 80 7 19 ozone 79.0
## 81 7 20 ozone 63.0
## 82 7 21 ozone 16.0
## 83 7 22 ozone NA
## 84 7 23 ozone NA
## 85 7 24 ozone 80.0
## 86 7 25 ozone 108.0
## 87 7 26 ozone 20.0
## 88 7 27 ozone 52.0
## 89 7 28 ozone 82.0
## 90 7 29 ozone 50.0
## 91 7 30 ozone 64.0
## 92 7 31 ozone 59.0
## 93 8 1 ozone 39.0
## 94 8 2 ozone 9.0
## 95 8 3 ozone 16.0
## 96 8 4 ozone 78.0
## 97 8 5 ozone 35.0
## 98 8 6 ozone 66.0
## 99 8 7 ozone 122.0
## 100 8 8 ozone 89.0
## 101 8 9 ozone 110.0
## 102 8 10 ozone NA
## 103 8 11 ozone NA
## 104 8 12 ozone 44.0
## 105 8 13 ozone 28.0
## 106 8 14 ozone 65.0
## 107 8 15 ozone NA
## 108 8 16 ozone 22.0
## 109 8 17 ozone 59.0
## 110 8 18 ozone 23.0
## 111 8 19 ozone 31.0
## 112 8 20 ozone 44.0
## 113 8 21 ozone 21.0
## 114 8 22 ozone 9.0
## 115 8 23 ozone NA
## 116 8 24 ozone 45.0
## 117 8 25 ozone 168.0
## 118 8 26 ozone 73.0
## 119 8 27 ozone NA
## 120 8 28 ozone 76.0
## 121 8 29 ozone 118.0
## 122 8 30 ozone 84.0
## 123 8 31 ozone 85.0
## 124 9 1 ozone 96.0
## 125 9 2 ozone 78.0
## 126 9 3 ozone 73.0
## 127 9 4 ozone 91.0
## 128 9 5 ozone 47.0
## 129 9 6 ozone 32.0
## 130 9 7 ozone 20.0
## 131 9 8 ozone 23.0
## 132 9 9 ozone 21.0
## 133 9 10 ozone 24.0
## 134 9 11 ozone 44.0
## 135 9 12 ozone 21.0
## 136 9 13 ozone 28.0
## 137 9 14 ozone 9.0
## 138 9 15 ozone 13.0
## 139 9 16 ozone 46.0
## 140 9 17 ozone 18.0
## 141 9 18 ozone 13.0
## 142 9 19 ozone 24.0
## 143 9 20 ozone 16.0
## 144 9 21 ozone 13.0
## 145 9 22 ozone 23.0
## 146 9 23 ozone 36.0
## 147 9 24 ozone 7.0
## 148 9 25 ozone 14.0
## 149 9 26 ozone 30.0
## 150 9 27 ozone NA
## 151 9 28 ozone 14.0
## 152 9 29 ozone 18.0
## 153 9 30 ozone 20.0
## 154 5 1 solar.r 190.0
## 155 5 2 solar.r 118.0
## 156 5 3 solar.r 149.0
## 157 5 4 solar.r 313.0
## 158 5 5 solar.r NA
## 159 5 6 solar.r NA
## 160 5 7 solar.r 299.0
## 161 5 8 solar.r 99.0
## 162 5 9 solar.r 19.0
## 163 5 10 solar.r 194.0
## 164 5 11 solar.r NA
## 165 5 12 solar.r 256.0
## 166 5 13 solar.r 290.0
## 167 5 14 solar.r 274.0
## 168 5 15 solar.r 65.0
## 169 5 16 solar.r 334.0
## 170 5 17 solar.r 307.0
## 171 5 18 solar.r 78.0
## 172 5 19 solar.r 322.0
## 173 5 20 solar.r 44.0
## 174 5 21 solar.r 8.0
## 175 5 22 solar.r 320.0
## 176 5 23 solar.r 25.0
## 177 5 24 solar.r 92.0
## 178 5 25 solar.r 66.0
## 179 5 26 solar.r 266.0
## 180 5 27 solar.r NA
## 181 5 28 solar.r 13.0
## 182 5 29 solar.r 252.0
## 183 5 30 solar.r 223.0
## 184 5 31 solar.r 279.0
## 185 6 1 solar.r 286.0
## 186 6 2 solar.r 287.0
## 187 6 3 solar.r 242.0
## 188 6 4 solar.r 186.0
## 189 6 5 solar.r 220.0
## 190 6 6 solar.r 264.0
## 191 6 7 solar.r 127.0
## 192 6 8 solar.r 273.0
## 193 6 9 solar.r 291.0
## 194 6 10 solar.r 323.0
## 195 6 11 solar.r 259.0
## 196 6 12 solar.r 250.0
## 197 6 13 solar.r 148.0
## 198 6 14 solar.r 332.0
## 199 6 15 solar.r 322.0
## 200 6 16 solar.r 191.0
## 201 6 17 solar.r 284.0
## 202 6 18 solar.r 37.0
## 203 6 19 solar.r 120.0
## 204 6 20 solar.r 137.0
## 205 6 21 solar.r 150.0
## 206 6 22 solar.r 59.0
## 207 6 23 solar.r 91.0
## 208 6 24 solar.r 250.0
## 209 6 25 solar.r 135.0
## 210 6 26 solar.r 127.0
## 211 6 27 solar.r 47.0
## 212 6 28 solar.r 98.0
## 213 6 29 solar.r 31.0
## 214 6 30 solar.r 138.0
## 215 7 1 solar.r 269.0
## 216 7 2 solar.r 248.0
## 217 7 3 solar.r 236.0
## 218 7 4 solar.r 101.0
## 219 7 5 solar.r 175.0
## 220 7 6 solar.r 314.0
## 221 7 7 solar.r 276.0
## 222 7 8 solar.r 267.0
## 223 7 9 solar.r 272.0
## 224 7 10 solar.r 175.0
## 225 7 11 solar.r 139.0
## 226 7 12 solar.r 264.0
## 227 7 13 solar.r 175.0
## 228 7 14 solar.r 291.0
## 229 7 15 solar.r 48.0
## 230 7 16 solar.r 260.0
## 231 7 17 solar.r 274.0
## 232 7 18 solar.r 285.0
## 233 7 19 solar.r 187.0
## 234 7 20 solar.r 220.0
## 235 7 21 solar.r 7.0
## 236 7 22 solar.r 258.0
## 237 7 23 solar.r 295.0
## 238 7 24 solar.r 294.0
## 239 7 25 solar.r 223.0
## 240 7 26 solar.r 81.0
## 241 7 27 solar.r 82.0
## 242 7 28 solar.r 213.0
## 243 7 29 solar.r 275.0
## 244 7 30 solar.r 253.0
## 245 7 31 solar.r 254.0
## 246 8 1 solar.r 83.0
## 247 8 2 solar.r 24.0
## 248 8 3 solar.r 77.0
## 249 8 4 solar.r NA
## 250 8 5 solar.r NA
## 251 8 6 solar.r NA
## 252 8 7 solar.r 255.0
## 253 8 8 solar.r 229.0
## 254 8 9 solar.r 207.0
## 255 8 10 solar.r 222.0
## 256 8 11 solar.r 137.0
## 257 8 12 solar.r 192.0
## 258 8 13 solar.r 273.0
## 259 8 14 solar.r 157.0
## 260 8 15 solar.r 64.0
## 261 8 16 solar.r 71.0
## 262 8 17 solar.r 51.0
## 263 8 18 solar.r 115.0
## 264 8 19 solar.r 244.0
## 265 8 20 solar.r 190.0
## 266 8 21 solar.r 259.0
## 267 8 22 solar.r 36.0
## 268 8 23 solar.r 255.0
## 269 8 24 solar.r 212.0
## 270 8 25 solar.r 238.0
## 271 8 26 solar.r 215.0
## 272 8 27 solar.r 153.0
## 273 8 28 solar.r 203.0
## 274 8 29 solar.r 225.0
## 275 8 30 solar.r 237.0
## 276 8 31 solar.r 188.0
## 277 9 1 solar.r 167.0
## 278 9 2 solar.r 197.0
## 279 9 3 solar.r 183.0
## 280 9 4 solar.r 189.0
## 281 9 5 solar.r 95.0
## 282 9 6 solar.r 92.0
## 283 9 7 solar.r 252.0
## 284 9 8 solar.r 220.0
## 285 9 9 solar.r 230.0
## 286 9 10 solar.r 259.0
## 287 9 11 solar.r 236.0
## 288 9 12 solar.r 259.0
## 289 9 13 solar.r 238.0
## 290 9 14 solar.r 24.0
## 291 9 15 solar.r 112.0
## 292 9 16 solar.r 237.0
## 293 9 17 solar.r 224.0
## 294 9 18 solar.r 27.0
## 295 9 19 solar.r 238.0
## 296 9 20 solar.r 201.0
## 297 9 21 solar.r 238.0
## 298 9 22 solar.r 14.0
## 299 9 23 solar.r 139.0
## 300 9 24 solar.r 49.0
## 301 9 25 solar.r 20.0
## 302 9 26 solar.r 193.0
## 303 9 27 solar.r 145.0
## 304 9 28 solar.r 191.0
## 305 9 29 solar.r 131.0
## 306 9 30 solar.r 223.0
## 307 5 1 wind 7.4
## 308 5 2 wind 8.0
## 309 5 3 wind 12.6
## 310 5 4 wind 11.5
## 311 5 5 wind 14.3
## 312 5 6 wind 14.9
## 313 5 7 wind 8.6
## 314 5 8 wind 13.8
## 315 5 9 wind 20.1
## 316 5 10 wind 8.6
## 317 5 11 wind 6.9
## 318 5 12 wind 9.7
## 319 5 13 wind 9.2
## 320 5 14 wind 10.9
## 321 5 15 wind 13.2
## 322 5 16 wind 11.5
## 323 5 17 wind 12.0
## 324 5 18 wind 18.4
## 325 5 19 wind 11.5
## 326 5 20 wind 9.7
## 327 5 21 wind 9.7
## 328 5 22 wind 16.6
## 329 5 23 wind 9.7
## 330 5 24 wind 12.0
## 331 5 25 wind 16.6
## 332 5 26 wind 14.9
## 333 5 27 wind 8.0
## 334 5 28 wind 12.0
## 335 5 29 wind 14.9
## 336 5 30 wind 5.7
## 337 5 31 wind 7.4
## 338 6 1 wind 8.6
## 339 6 2 wind 9.7
## 340 6 3 wind 16.1
## 341 6 4 wind 9.2
## 342 6 5 wind 8.6
## 343 6 6 wind 14.3
## 344 6 7 wind 9.7
## 345 6 8 wind 6.9
## 346 6 9 wind 13.8
## 347 6 10 wind 11.5
## 348 6 11 wind 10.9
## 349 6 12 wind 9.2
## 350 6 13 wind 8.0
## 351 6 14 wind 13.8
## 352 6 15 wind 11.5
## 353 6 16 wind 14.9
## 354 6 17 wind 20.7
## 355 6 18 wind 9.2
## 356 6 19 wind 11.5
## 357 6 20 wind 10.3
## 358 6 21 wind 6.3
## 359 6 22 wind 1.7
## 360 6 23 wind 4.6
## 361 6 24 wind 6.3
## 362 6 25 wind 8.0
## 363 6 26 wind 8.0
## 364 6 27 wind 10.3
## 365 6 28 wind 11.5
## 366 6 29 wind 14.9
## 367 6 30 wind 8.0
## 368 7 1 wind 4.1
## 369 7 2 wind 9.2
## 370 7 3 wind 9.2
## 371 7 4 wind 10.9
## 372 7 5 wind 4.6
## 373 7 6 wind 10.9
## 374 7 7 wind 5.1
## 375 7 8 wind 6.3
## 376 7 9 wind 5.7
## 377 7 10 wind 7.4
## 378 7 11 wind 8.6
## 379 7 12 wind 14.3
## 380 7 13 wind 14.9
## 381 7 14 wind 14.9
## 382 7 15 wind 14.3
## 383 7 16 wind 6.9
## 384 7 17 wind 10.3
## 385 7 18 wind 6.3
## 386 7 19 wind 5.1
## 387 7 20 wind 11.5
## 388 7 21 wind 6.9
## 389 7 22 wind 9.7
## 390 7 23 wind 11.5
## 391 7 24 wind 8.6
## 392 7 25 wind 8.0
## 393 7 26 wind 8.6
## 394 7 27 wind 12.0
## 395 7 28 wind 7.4
## 396 7 29 wind 7.4
## 397 7 30 wind 7.4
## 398 7 31 wind 9.2
## 399 8 1 wind 6.9
## 400 8 2 wind 13.8
## 401 8 3 wind 7.4
## 402 8 4 wind 6.9
## 403 8 5 wind 7.4
## 404 8 6 wind 4.6
## 405 8 7 wind 4.0
## 406 8 8 wind 10.3
## 407 8 9 wind 8.0
## 408 8 10 wind 8.6
## 409 8 11 wind 11.5
## 410 8 12 wind 11.5
## 411 8 13 wind 11.5
## 412 8 14 wind 9.7
## 413 8 15 wind 11.5
## 414 8 16 wind 10.3
## 415 8 17 wind 6.3
## 416 8 18 wind 7.4
## 417 8 19 wind 10.9
## 418 8 20 wind 10.3
## 419 8 21 wind 15.5
## 420 8 22 wind 14.3
## 421 8 23 wind 12.6
## 422 8 24 wind 9.7
## 423 8 25 wind 3.4
## 424 8 26 wind 8.0
## 425 8 27 wind 5.7
## 426 8 28 wind 9.7
## 427 8 29 wind 2.3
## 428 8 30 wind 6.3
## 429 8 31 wind 6.3
## 430 9 1 wind 6.9
## 431 9 2 wind 5.1
## 432 9 3 wind 2.8
## 433 9 4 wind 4.6
## 434 9 5 wind 7.4
## 435 9 6 wind 15.5
## 436 9 7 wind 10.9
## 437 9 8 wind 10.3
## 438 9 9 wind 10.9
## 439 9 10 wind 9.7
## 440 9 11 wind 14.9
## 441 9 12 wind 15.5
## 442 9 13 wind 6.3
## 443 9 14 wind 10.9
## 444 9 15 wind 11.5
## 445 9 16 wind 6.9
## 446 9 17 wind 13.8
## 447 9 18 wind 10.3
## 448 9 19 wind 10.3
## 449 9 20 wind 8.0
## 450 9 21 wind 12.6
## 451 9 22 wind 9.2
## 452 9 23 wind 10.3
## 453 9 24 wind 10.3
## 454 9 25 wind 16.6
## 455 9 26 wind 6.9
## 456 9 27 wind 13.2
## 457 9 28 wind 14.3
## 458 9 29 wind 8.0
## 459 9 30 wind 11.5
## 460 5 1 temp 67.0
## 461 5 2 temp 72.0
## 462 5 3 temp 74.0
## 463 5 4 temp 62.0
## 464 5 5 temp 56.0
## 465 5 6 temp 66.0
## 466 5 7 temp 65.0
## 467 5 8 temp 59.0
## 468 5 9 temp 61.0
## 469 5 10 temp 69.0
## 470 5 11 temp 74.0
## 471 5 12 temp 69.0
## 472 5 13 temp 66.0
## 473 5 14 temp 68.0
## 474 5 15 temp 58.0
## 475 5 16 temp 64.0
## 476 5 17 temp 66.0
## 477 5 18 temp 57.0
## 478 5 19 temp 68.0
## 479 5 20 temp 62.0
## 480 5 21 temp 59.0
## 481 5 22 temp 73.0
## 482 5 23 temp 61.0
## 483 5 24 temp 61.0
## 484 5 25 temp 57.0
## 485 5 26 temp 58.0
## 486 5 27 temp 57.0
## 487 5 28 temp 67.0
## 488 5 29 temp 81.0
## 489 5 30 temp 79.0
## 490 5 31 temp 76.0
## 491 6 1 temp 78.0
## 492 6 2 temp 74.0
## 493 6 3 temp 67.0
## 494 6 4 temp 84.0
## 495 6 5 temp 85.0
## 496 6 6 temp 79.0
## 497 6 7 temp 82.0
## 498 6 8 temp 87.0
## 499 6 9 temp 90.0
## 500 6 10 temp 87.0
## 501 6 11 temp 93.0
## 502 6 12 temp 92.0
## 503 6 13 temp 82.0
## 504 6 14 temp 80.0
## 505 6 15 temp 79.0
## 506 6 16 temp 77.0
## 507 6 17 temp 72.0
## 508 6 18 temp 65.0
## 509 6 19 temp 73.0
## 510 6 20 temp 76.0
## 511 6 21 temp 77.0
## 512 6 22 temp 76.0
## 513 6 23 temp 76.0
## 514 6 24 temp 76.0
## 515 6 25 temp 75.0
## 516 6 26 temp 78.0
## 517 6 27 temp 73.0
## 518 6 28 temp 80.0
## 519 6 29 temp 77.0
## 520 6 30 temp 83.0
## 521 7 1 temp 84.0
## 522 7 2 temp 85.0
## 523 7 3 temp 81.0
## 524 7 4 temp 84.0
## 525 7 5 temp 83.0
## 526 7 6 temp 83.0
## 527 7 7 temp 88.0
## 528 7 8 temp 92.0
## 529 7 9 temp 92.0
## 530 7 10 temp 89.0
## 531 7 11 temp 82.0
## 532 7 12 temp 73.0
## 533 7 13 temp 81.0
## 534 7 14 temp 91.0
## 535 7 15 temp 80.0
## 536 7 16 temp 81.0
## 537 7 17 temp 82.0
## 538 7 18 temp 84.0
## 539 7 19 temp 87.0
## 540 7 20 temp 85.0
## 541 7 21 temp 74.0
## 542 7 22 temp 81.0
## 543 7 23 temp 82.0
## 544 7 24 temp 86.0
## 545 7 25 temp 85.0
## 546 7 26 temp 82.0
## 547 7 27 temp 86.0
## 548 7 28 temp 88.0
## 549 7 29 temp 86.0
## 550 7 30 temp 83.0
## 551 7 31 temp 81.0
## 552 8 1 temp 81.0
## 553 8 2 temp 81.0
## 554 8 3 temp 82.0
## 555 8 4 temp 86.0
## 556 8 5 temp 85.0
## 557 8 6 temp 87.0
## 558 8 7 temp 89.0
## 559 8 8 temp 90.0
## 560 8 9 temp 90.0
## 561 8 10 temp 92.0
## 562 8 11 temp 86.0
## 563 8 12 temp 86.0
## 564 8 13 temp 82.0
## 565 8 14 temp 80.0
## 566 8 15 temp 79.0
## 567 8 16 temp 77.0
## 568 8 17 temp 79.0
## 569 8 18 temp 76.0
## 570 8 19 temp 78.0
## 571 8 20 temp 78.0
## 572 8 21 temp 77.0
## 573 8 22 temp 72.0
## 574 8 23 temp 75.0
## 575 8 24 temp 79.0
## 576 8 25 temp 81.0
## 577 8 26 temp 86.0
## 578 8 27 temp 88.0
## 579 8 28 temp 97.0
## 580 8 29 temp 94.0
## 581 8 30 temp 96.0
## 582 8 31 temp 94.0
## 583 9 1 temp 91.0
## 584 9 2 temp 92.0
## 585 9 3 temp 93.0
## 586 9 4 temp 93.0
## 587 9 5 temp 87.0
## 588 9 6 temp 84.0
## 589 9 7 temp 80.0
## 590 9 8 temp 78.0
## 591 9 9 temp 75.0
## 592 9 10 temp 73.0
## 593 9 11 temp 81.0
## 594 9 12 temp 76.0
## 595 9 13 temp 77.0
## 596 9 14 temp 71.0
## 597 9 15 temp 71.0
## 598 9 16 temp 78.0
## 599 9 17 temp 67.0
## 600 9 18 temp 76.0
## 601 9 19 temp 68.0
## 602 9 20 temp 82.0
## 603 9 21 temp 64.0
## 604 9 22 temp 71.0
## 605 9 23 temp 81.0
## 606 9 24 temp 69.0
## 607 9 25 temp 63.0
## 608 9 26 temp 70.0
## 609 9 27 temp 77.0
## 610 9 28 temp 75.0
## 611 9 29 temp 76.0
## 612 9 30 temp 68.0
(acast_result <- acast(aqm, day ~ month ~ climate_variable, na.rm = TRUE))
## Using climate_value as value column: use value.var to override.
## , , ozone
##
## 5 6 7 8 9
## 1 41 NA 135 39 96
## 2 36 NA 49 9 78
## 3 12 NA 32 16 73
## 4 18 NA NA 78 91
## 5 NA NA 64 35 47
## 6 28 NA 40 66 32
## 7 23 29 77 122 20
## 8 19 NA 97 89 23
## 9 8 71 97 110 21
## 10 NA 39 85 NA 24
## 11 7 NA NA NA 44
## 12 16 NA 10 44 21
## 13 11 23 27 28 28
## 14 14 NA NA 65 9
## 15 18 NA 7 NA 13
## 16 14 21 48 22 46
## 17 34 37 35 59 18
## 18 6 20 61 23 13
## 19 30 12 79 31 24
## 20 11 13 63 44 16
## 21 1 NA 16 21 13
## 22 11 NA NA 9 23
## 23 4 NA NA NA 36
## 24 32 NA 80 45 7
## 25 NA NA 108 168 14
## 26 NA NA 20 73 30
## 27 NA NA 52 NA NA
## 28 23 NA 82 76 14
## 29 45 NA 50 118 18
## 30 115 NA 64 84 20
## 31 37 NA 59 85 NA
##
## , , solar.r
##
## 5 6 7 8 9
## 1 190 286 269 83 167
## 2 118 287 248 24 197
## 3 149 242 236 77 183
## 4 313 186 101 NA 189
## 5 NA 220 175 NA 95
## 6 NA 264 314 NA 92
## 7 299 127 276 255 252
## 8 99 273 267 229 220
## 9 19 291 272 207 230
## 10 194 323 175 222 259
## 11 NA 259 139 137 236
## 12 256 250 264 192 259
## 13 290 148 175 273 238
## 14 274 332 291 157 24
## 15 65 322 48 64 112
## 16 334 191 260 71 237
## 17 307 284 274 51 224
## 18 78 37 285 115 27
## 19 322 120 187 244 238
## 20 44 137 220 190 201
## 21 8 150 7 259 238
## 22 320 59 258 36 14
## 23 25 91 295 255 139
## 24 92 250 294 212 49
## 25 66 135 223 238 20
## 26 266 127 81 215 193
## 27 NA 47 82 153 145
## 28 13 98 213 203 191
## 29 252 31 275 225 131
## 30 223 138 253 237 223
## 31 279 NA 254 188 NA
##
## , , wind
##
## 5 6 7 8 9
## 1 7.4 8.6 4.1 6.9 6.9
## 2 8.0 9.7 9.2 13.8 5.1
## 3 12.6 16.1 9.2 7.4 2.8
## 4 11.5 9.2 10.9 6.9 4.6
## 5 14.3 8.6 4.6 7.4 7.4
## 6 14.9 14.3 10.9 4.6 15.5
## 7 8.6 9.7 5.1 4.0 10.9
## 8 13.8 6.9 6.3 10.3 10.3
## 9 20.1 13.8 5.7 8.0 10.9
## 10 8.6 11.5 7.4 8.6 9.7
## 11 6.9 10.9 8.6 11.5 14.9
## 12 9.7 9.2 14.3 11.5 15.5
## 13 9.2 8.0 14.9 11.5 6.3
## 14 10.9 13.8 14.9 9.7 10.9
## 15 13.2 11.5 14.3 11.5 11.5
## 16 11.5 14.9 6.9 10.3 6.9
## 17 12.0 20.7 10.3 6.3 13.8
## 18 18.4 9.2 6.3 7.4 10.3
## 19 11.5 11.5 5.1 10.9 10.3
## 20 9.7 10.3 11.5 10.3 8.0
## 21 9.7 6.3 6.9 15.5 12.6
## 22 16.6 1.7 9.7 14.3 9.2
## 23 9.7 4.6 11.5 12.6 10.3
## 24 12.0 6.3 8.6 9.7 10.3
## 25 16.6 8.0 8.0 3.4 16.6
## 26 14.9 8.0 8.6 8.0 6.9
## 27 8.0 10.3 12.0 5.7 13.2
## 28 12.0 11.5 7.4 9.7 14.3
## 29 14.9 14.9 7.4 2.3 8.0
## 30 5.7 8.0 7.4 6.3 11.5
## 31 7.4 NA 9.2 6.3 NA
##
## , , temp
##
## 5 6 7 8 9
## 1 67 78 84 81 91
## 2 72 74 85 81 92
## 3 74 67 81 82 93
## 4 62 84 84 86 93
## 5 56 85 83 85 87
## 6 66 79 83 87 84
## 7 65 82 88 89 80
## 8 59 87 92 90 78
## 9 61 90 92 90 75
## 10 69 87 89 92 73
## 11 74 93 82 86 81
## 12 69 92 73 86 76
## 13 66 82 81 82 77
## 14 68 80 91 80 71
## 15 58 79 80 79 71
## 16 64 77 81 77 78
## 17 66 72 82 79 67
## 18 57 65 84 76 76
## 19 68 73 87 78 68
## 20 62 76 85 78 82
## 21 59 77 74 77 64
## 22 73 76 81 72 71
## 23 61 76 82 75 81
## 24 61 76 86 79 69
## 25 57 75 85 81 63
## 26 58 78 82 86 70
## 27 57 73 86 88 77
## 28 67 80 88 97 75
## 29 81 77 86 94 76
## 30 79 83 83 96 68
## 31 76 NA 81 94 NA
acast(aqm, month ~ climate_variable, mean, na.rm = TRUE)
## Using climate_value as value column: use value.var to override.
## ozone solar.r wind temp
## 5 23.61538 181.2963 11.622581 65.54839
## 6 29.44444 190.1667 10.266667 79.10000
## 7 59.11538 216.4839 8.941935 83.90323
## 8 59.96154 171.8571 8.793548 83.96774
## 9 31.44828 167.4333 10.180000 76.90000
acast_result
## , , ozone
##
## 5 6 7 8 9
## 1 41 NA 135 39 96
## 2 36 NA 49 9 78
## 3 12 NA 32 16 73
## 4 18 NA NA 78 91
## 5 NA NA 64 35 47
## 6 28 NA 40 66 32
## 7 23 29 77 122 20
## 8 19 NA 97 89 23
## 9 8 71 97 110 21
## 10 NA 39 85 NA 24
## 11 7 NA NA NA 44
## 12 16 NA 10 44 21
## 13 11 23 27 28 28
## 14 14 NA NA 65 9
## 15 18 NA 7 NA 13
## 16 14 21 48 22 46
## 17 34 37 35 59 18
## 18 6 20 61 23 13
## 19 30 12 79 31 24
## 20 11 13 63 44 16
## 21 1 NA 16 21 13
## 22 11 NA NA 9 23
## 23 4 NA NA NA 36
## 24 32 NA 80 45 7
## 25 NA NA 108 168 14
## 26 NA NA 20 73 30
## 27 NA NA 52 NA NA
## 28 23 NA 82 76 14
## 29 45 NA 50 118 18
## 30 115 NA 64 84 20
## 31 37 NA 59 85 NA
##
## , , solar.r
##
## 5 6 7 8 9
## 1 190 286 269 83 167
## 2 118 287 248 24 197
## 3 149 242 236 77 183
## 4 313 186 101 NA 189
## 5 NA 220 175 NA 95
## 6 NA 264 314 NA 92
## 7 299 127 276 255 252
## 8 99 273 267 229 220
## 9 19 291 272 207 230
## 10 194 323 175 222 259
## 11 NA 259 139 137 236
## 12 256 250 264 192 259
## 13 290 148 175 273 238
## 14 274 332 291 157 24
## 15 65 322 48 64 112
## 16 334 191 260 71 237
## 17 307 284 274 51 224
## 18 78 37 285 115 27
## 19 322 120 187 244 238
## 20 44 137 220 190 201
## 21 8 150 7 259 238
## 22 320 59 258 36 14
## 23 25 91 295 255 139
## 24 92 250 294 212 49
## 25 66 135 223 238 20
## 26 266 127 81 215 193
## 27 NA 47 82 153 145
## 28 13 98 213 203 191
## 29 252 31 275 225 131
## 30 223 138 253 237 223
## 31 279 NA 254 188 NA
##
## , , wind
##
## 5 6 7 8 9
## 1 7.4 8.6 4.1 6.9 6.9
## 2 8.0 9.7 9.2 13.8 5.1
## 3 12.6 16.1 9.2 7.4 2.8
## 4 11.5 9.2 10.9 6.9 4.6
## 5 14.3 8.6 4.6 7.4 7.4
## 6 14.9 14.3 10.9 4.6 15.5
## 7 8.6 9.7 5.1 4.0 10.9
## 8 13.8 6.9 6.3 10.3 10.3
## 9 20.1 13.8 5.7 8.0 10.9
## 10 8.6 11.5 7.4 8.6 9.7
## 11 6.9 10.9 8.6 11.5 14.9
## 12 9.7 9.2 14.3 11.5 15.5
## 13 9.2 8.0 14.9 11.5 6.3
## 14 10.9 13.8 14.9 9.7 10.9
## 15 13.2 11.5 14.3 11.5 11.5
## 16 11.5 14.9 6.9 10.3 6.9
## 17 12.0 20.7 10.3 6.3 13.8
## 18 18.4 9.2 6.3 7.4 10.3
## 19 11.5 11.5 5.1 10.9 10.3
## 20 9.7 10.3 11.5 10.3 8.0
## 21 9.7 6.3 6.9 15.5 12.6
## 22 16.6 1.7 9.7 14.3 9.2
## 23 9.7 4.6 11.5 12.6 10.3
## 24 12.0 6.3 8.6 9.7 10.3
## 25 16.6 8.0 8.0 3.4 16.6
## 26 14.9 8.0 8.6 8.0 6.9
## 27 8.0 10.3 12.0 5.7 13.2
## 28 12.0 11.5 7.4 9.7 14.3
## 29 14.9 14.9 7.4 2.3 8.0
## 30 5.7 8.0 7.4 6.3 11.5
## 31 7.4 NA 9.2 6.3 NA
##
## , , temp
##
## 5 6 7 8 9
## 1 67 78 84 81 91
## 2 72 74 85 81 92
## 3 74 67 81 82 93
## 4 62 84 84 86 93
## 5 56 85 83 85 87
## 6 66 79 83 87 84
## 7 65 82 88 89 80
## 8 59 87 92 90 78
## 9 61 90 92 90 75
## 10 69 87 89 92 73
## 11 74 93 82 86 81
## 12 69 92 73 86 76
## 13 66 82 81 82 77
## 14 68 80 91 80 71
## 15 58 79 80 79 71
## 16 64 77 81 77 78
## 17 66 72 82 79 67
## 18 57 65 84 76 76
## 19 68 73 87 78 68
## 20 62 76 85 78 82
## 21 59 77 74 77 64
## 22 73 76 81 72 71
## 23 61 76 82 75 81
## 24 61 76 86 79 69
## 25 57 75 85 81 63
## 26 58 78 82 86 70
## 27 57 73 86 88 77
## 28 67 80 88 97 75
## 29 81 77 86 94 76
## 30 79 83 83 96 68
## 31 76 NA 81 94 NA
acast_result[22,5,] # arrays are accessed
## ozone solar.r wind temp
## 23.0 14.0 9.2 71.0
grepl returns a logic vector given an expression
letters
## [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
## [18] "r" "s" "t" "u" "v" "w" "x" "y" "z"
grep("[a-c]", letters)
## [1] 1 2 3
grep("[a-z]", letters)
## [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
## [24] 24 25 26
grepl("[a-c]", letters)
## [1] TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [12] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
## [23] FALSE FALSE FALSE FALSE
grepl("[a-z]", letters)
## [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## [15] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
EuropeLeagueTransfers.Rmd